#include "MBAxisAlignedBoundingBox.h"

const MBuint X = 0u;
const MBuint Y = 1u;
const MBuint Z = 2u;

/**
  *	Constructs a new MBAxisAlignedBoundingBox with a min-point and a max-point
  *
  * @param min min-point
  * @param max max-point
  */
MBAxisAlignedBoundingBox::MBAxisAlignedBoundingBox( const MBVec3 &min, const MBVec3 &max ) :
	mMin( min ),
	mMax( max )
{
}

/**
  *	Returns true when this axis aligned bounding box is intersecting with the
  * given camera view frustum, false otherwise
  *
  * @param frustum camera view frustum that is used for the intersection estimation
  * @return true when this axis aligned bounding box is intersecting with the given camera view frustum, false otherwise
  */
bool MBAxisAlignedBoundingBox::IsIntersectingWithCameraViewFrustum( const MBCameraViewFrustum &frustum ) const
{
	return frustum.IsAxisAlignedBoxIntersectingFrustum( mMin, mMax );
}

/**
  *	Returns true when the given point is inside of this axis aligned bounding
  * box, false otherwise
  *
  * @param point point in 3D space
  * @return true when the given point is inside of this axis aligned bounding box, false otherwise
  */
bool MBAxisAlignedBoundingBox::IsPointInside( const MBVec3 &point ) const
{
	if (point[X] < mMin[X] || point[Y] < mMin[Y] || point[Z] < mMin[Z] ||
		point[X] > mMax[X] || point[Y] > mMax[Y] || point[Z] > mMax[Z])
		return false;

	return true;
}

/**
  *	Returns the maximum point of this axis aligned bounding box
  * @return maximum point of this axis aligned bounding box
  */
const MBVec3 &MBAxisAlignedBoundingBox::GetMax( void ) const
{
	return mMax;
}

/**
  *	Returns the minimum point of this axis aligned bounding box
  * @return minimum point of this axis aligned bounding box
  */
const MBVec3 &MBAxisAlignedBoundingBox::GetMin( void ) const
{
	return mMin;
}